package pxene.phantomJs;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class HttpUtils {  
	
	private static final String userAgent = "Mozilla/5.0 (Windows NT 6.0) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.41 Safari/535.1";
	static {
		System.setProperty("phantomjs.binary.path",
				"C:/Users/chenjinghui/Desktop/phantomjs-2.1.1-windows/bin/phantomjs.exe");
		System.setProperty("phantomjs.page.settings.userAgent", userAgent);
	}
	
	
    public static String getAjaxCotnent(String url) throws IOException {  
        Runtime rt = Runtime.getRuntime();  
        Process p = rt.exec("C:/Users/chenjinghui/Desktop/phantomjs-2.1.1-windows/bin/phantomjs.exe D:/code.js "+url);//这里我的codes.js是保存在c盘下面的phantomjs目录  
        
        InputStream is = p.getInputStream();  
        BufferedReader br = new BufferedReader(new InputStreamReader(is));  
        StringBuffer sbf = new StringBuffer();  
        String tmp = "";  
        while((tmp = br.readLine())!=null){  
            sbf.append(tmp);  
        }  
        System.out.println(sbf.toString());  
        return sbf.toString();  
    }  
  
    public static void main(String[] args) throws IOException {  
        String ajaxCotnent = getAjaxCotnent("http://www.toutiao.com/");  
        System.out.println(ajaxCotnent);
    }  
}  